﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using PhotoGallery.Application;

namespace PhotoGallery.Application.HttpModule
{
    public class SessionFilter : IHttpModule
    {


        public void Dispose()
        {
            // do noting
        }

        public void Init(HttpApplication context)
        {
            context.PreRequestHandlerExecute += application_PreRequestHandlerExecute;
        }

        /// <summary>
        /// 判断有无Session
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void application_PreRequestHandlerExecute(object sender, EventArgs e)
        {
            HttpApplication application = (HttpApplication)sender;

            HttpContext context = application.Context;

            HttpRequest request = application.Request;

            HttpResponse response = application.Response;

            #region 处理用户登录


            

            if (request.Url.OriginalString.ToLower().Contains("relogin"))
            {
                
            }
            if (UserSession.OnlineAccount == null)
            {
                response.RedirectLocation = "~/account/relogin?reason=该用户暂时没有登录！";
            }


            #endregion

        }
    }
}
